{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline \n",
    "from scipy import stats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = pd.read_csv('../data/train_drop_col_row.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test = pd.read_csv('../data/train_x_drop_col_row.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(13602, 121)\n",
      "(8122, 120)\n"
     ]
    }
   ],
   "source": [
    "print(train.shape)\n",
    "print(test.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_x = train.drop(['y'],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(21724, 120)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = pd.concat([train_x,test])\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['cust_id', 'cust_group', 'y', 'x_1', 'x_2', 'x_3', 'x_4', 'x_5',\n",
       "       'x_6', 'x_7', 'x_8', 'x_9', 'x_10', 'x_11', 'x_12', 'x_13', 'x_14',\n",
       "       'x_15', 'x_16', 'x_17', 'x_18', 'x_19', 'x_20', 'x_21', 'x_22',\n",
       "       'x_23', 'x_24', 'x_25', 'x_26', 'x_27', 'x_28', 'x_29', 'x_30',\n",
       "       'x_31', 'x_32', 'x_33', 'x_34', 'x_35', 'x_36', 'x_37', 'x_38',\n",
       "       'x_39', 'x_40', 'x_41', 'x_42', 'x_43', 'x_44', 'x_45', 'x_46',\n",
       "       'x_47', 'x_48', 'x_49', 'x_50', 'x_51', 'x_52', 'x_53', 'x_54',\n",
       "       'x_55', 'x_56', 'x_57', 'x_58', 'x_59', 'x_60', 'x_61', 'x_62',\n",
       "       'x_63', 'x_64', 'x_65', 'x_66', 'x_67', 'x_68', 'x_69', 'x_70',\n",
       "       'x_71', 'x_72', 'x_73', 'x_74', 'x_75', 'x_76', 'x_77', 'x_78',\n",
       "       'x_79', 'x_80', 'x_81', 'x_82', 'x_83', 'x_84', 'x_85', 'x_86',\n",
       "       'x_87', 'x_88', 'x_89', 'x_90', 'x_91', 'x_93', 'x_95', 'x_96',\n",
       "       'x_97', 'x_98', 'x_99', 'x_100', 'x_101', 'x_139', 'x_140',\n",
       "       'x_141', 'x_142', 'x_143', 'x_144', 'x_145', 'x_146', 'x_147',\n",
       "       'x_148', 'x_149', 'x_150', 'x_151', 'x_152', 'x_153', 'x_154',\n",
       "       'x_155', 'x_156', 'x_157'], dtype=object)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.columns.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "##哑编码\n",
    "column_dummy = ['x_1', 'x_2', 'x_3', 'x_4', 'x_5',\n",
    "       'x_6', 'x_7', 'x_8', 'x_9', 'x_10', 'x_11', 'x_12', 'x_13', 'x_14',\n",
    "       'x_15', 'x_16', 'x_17', 'x_18', 'x_19', 'x_20', 'x_21', 'x_22',\n",
    "       'x_23', 'x_24', 'x_25', 'x_26', 'x_27', 'x_28', 'x_29', 'x_30',\n",
    "       'x_31', 'x_32', 'x_33', 'x_34', 'x_35', 'x_36', 'x_37', 'x_38',\n",
    "       'x_39', 'x_40', 'x_41', 'x_42', 'x_43', 'x_44', 'x_45', 'x_46',\n",
    "       'x_47', 'x_48', 'x_49', 'x_50', 'x_51', 'x_52', 'x_53', 'x_54',\n",
    "       'x_55', 'x_56', 'x_57', 'x_58', 'x_59', 'x_60', 'x_61', 'x_62',\n",
    "       'x_63', 'x_64', 'x_65', 'x_66', 'x_67', 'x_68', 'x_69', 'x_70',\n",
    "       'x_71', 'x_72', 'x_73', 'x_74', 'x_75', 'x_76', 'x_77', 'x_78',\n",
    "       'x_79', 'x_80', 'x_81', 'x_82', 'x_83', 'x_84', 'x_85', 'x_86',\n",
    "       'x_87', 'x_88', 'x_89', 'x_90', 'x_91', 'x_93', 'x_95', 'x_96',\n",
    "       'x_97', 'x_98', 'x_99', 'x_100', 'x_101', 'x_139', 'x_140',\n",
    "       'x_141', 'x_142', 'x_143', 'x_144', 'x_145', 'x_146', 'x_147',\n",
    "       'x_148', 'x_149', 'x_150', 'x_151', 'x_152', 'x_153', 'x_154',\n",
    "       'x_155', 'x_156', 'x_157']\n",
    "\n",
    "for i in column_dummy:\n",
    "    dummies_df = pd.get_dummies(x[i]).rename(columns=lambda x: i + str(x))\n",
    "    x = pd.concat([x, dummies_df], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(21724, 17541)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(13602, 17541)\n",
      "(8122, 17541)\n"
     ]
    }
   ],
   "source": [
    "train_X = x[0:13602]\n",
    "test_X = x[13602:21724]\n",
    "print(train_X.shape)\n",
    "print(test_X.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(13602, 17542)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\ipykernel\\__main__.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  if __name__ == '__main__':\n"
     ]
    }
   ],
   "source": [
    "train_X['y'] = train['y']\n",
    "print(train_X.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cust_id</th>\n",
       "      <th>cust_group</th>\n",
       "      <th>x_1</th>\n",
       "      <th>x_2</th>\n",
       "      <th>x_3</th>\n",
       "      <th>x_4</th>\n",
       "      <th>x_5</th>\n",
       "      <th>x_6</th>\n",
       "      <th>x_7</th>\n",
       "      <th>x_8</th>\n",
       "      <th>...</th>\n",
       "      <th>x_1562</th>\n",
       "      <th>x_1563</th>\n",
       "      <th>x_157-99</th>\n",
       "      <th>x_1571</th>\n",
       "      <th>x_1572</th>\n",
       "      <th>x_1573</th>\n",
       "      <th>x_1574</th>\n",
       "      <th>x_15710</th>\n",
       "      <th>x_15711</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>110000</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0.354167</td>\n",
       "      <td>0.604988</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>110001</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0.125000</td>\n",
       "      <td>0.012058</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>110002</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.565979</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>110003</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.316209</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>110004</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.008061</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 17542 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   cust_id cust_group       x_1       x_2  x_3  x_4  x_5  x_6  x_7  x_8 ...  \\\n",
       "0   110000    group_3  0.354167  0.604988  -99  -99  -99  -99  -99  -99 ...   \n",
       "1   110001    group_3  0.125000  0.012058  -99  -99  -99  -99  -99  -99 ...   \n",
       "2   110002    group_3  0.333333  0.565979    0    0    0    0    0    0 ...   \n",
       "3   110003    group_3  0.208333  0.316209    0    0    0    0    1    1 ...   \n",
       "4   110004    group_3  0.208333  0.008061  -99  -99  -99  -99  -99  -99 ...   \n",
       "\n",
       "   x_1562  x_1563  x_157-99  x_1571  x_1572  x_1573  x_1574  x_15710  x_15711  \\\n",
       "0       0       1         1       0       0       0       0        0        0   \n",
       "1       1       0         0       0       1       0       0        0        0   \n",
       "2       1       0         0       0       1       0       0        0        0   \n",
       "3       1       0         0       0       0       0       1        0        0   \n",
       "4       1       0         0       1       0       0       0        0        0   \n",
       "\n",
       "   y  \n",
       "0  0  \n",
       "1  0  \n",
       "2  0  \n",
       "3  0  \n",
       "4  0  \n",
       "\n",
       "[5 rows x 17542 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_X.to_csv('dummy_feature_train_xy.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x26080add2b0>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPkAAADuCAYAAAD7nKGzAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAGAxJREFUeJzt3XmUFOW9xvHv2z07+7CDSCHIIhpU\nwDWiVzSoZVCWG0WMejV6olFjzI1Wco2XXG+0TDTXGKPRRI27aIxLKI4ScWENIioKsmMpoOzDbDBL\nd9f9o1oFHKCH6Z63qvr3OaePh2G6+xmc57xvVVe9r/I8DyFEdMV0BxBC5JaUXIiIk5ILEXFSciEi\nTkouR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xy591lqS0lJW8lhuV0xT85dw1QqjlOWGzF32P+Ptc2d+oOE1ZS8lZmWE4P4Of4\nO61K2Zu2Hf+cxr2ubdboDhN2UnJNDMvpCFyMv5vLUZrjBMVs4M/A32Ranj1S8gAwLOcE/LJfQP7d\n/LIVeAz4i2uby3WHiSIpeYAYltMemAz8ADhWc5xcSuFvavFn4CU5U55bUvKAMiznUOCc9GM04R/h\ntwMzgOnAq65tymKZrURKHgKG5RTjryJrph+HaQ2UuQ/wSz0d+Jdrm0nNefKSlDyEDMs5HDgB/5bX\n44Cj0X/NfDX+KqgL04+5rm1+rjeSACl5JKRvkBmIf5b+KGAocAjQA//S2mzdCluPv9rKRvyNCT7C\n30duCbDWtc1Ult5HZJGUPOLS9713Bnril74nfvFL9vpWtdefq/HL/NXDtc2K3KYVuSAlFyLiZPkn\nISJOSi5ExEnJhYg4KbkQESclFyLipORCRJyUXIiIk5ILEXFSciEiTkouRMRJyYWIOCm5EBEnJRci\n4qTkQkSclFyIiJOSCxFxUnIhIk5KLkTEScmFiDgpuRARJyUXIuKk5EJEnJRciIiTkgsRcVJyISJO\nSi5ExEnJhYg4KbkQESclFyLipORCRJyUXIiI+3/0gHbImd3ktwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "train_X['y'].value_counts().plot.pie(autopct = '%1.2f%%')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test_X.to_csv('dummy_feature_train_x.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "###woe特征\n",
    "def woe_single(DF,Y,X):\n",
    "    if X.nunique()>11:\n",
    "        r = 0\n",
    "        bad=Y.sum()      #坏客户数(假设因变量列为1的是坏客户)\n",
    "        good=Y.count()-bad  #好客户数\n",
    "        n=5\n",
    "        while np.abs(r) < 1:\n",
    "            d1 = pd.DataFrame({\"X\": X, \"Y\": Y, \"Bucket\": pd.qcut(X, n,duplicates='drop')})\n",
    "            d2 = d1.groupby('Bucket', as_index = False)\n",
    "            r, p = stats.spearmanr(d2.mean().X, d2.mean().Y)\n",
    "            n = n - 1\n",
    "        d3 = pd.DataFrame(d2.X.min(), columns = ['min'])\n",
    "        d3['min']=d2.min().X    \n",
    "        d3['max'] = d2.max().X\n",
    "        d3['sum'] = d2.sum().Y\n",
    "        d3['total'] = d2.count().Y\n",
    "        d3['bad_rate'] = d2.mean().Y\n",
    "        d3['group_rate']=d3['total']/(bad+good)\n",
    "        d3['woe']=np.log((d3['bad_rate']/(1-d3['bad_rate']))/(bad/good))\n",
    "        d3['iv']=(d3['sum']/bad-((d3['total']-d3['sum'])/good))*d3['woe']\n",
    "        iv=d3['iv'].sum()\n",
    "        if iv!=0.0 and len(d2)>1:\n",
    "            d3['iv_sum']=iv\n",
    "            woe=list(d3['woe'].round(6))\n",
    "            cut=list(d3['min'].round(6))\n",
    "            cut1=list(d3['max'].round(6))\n",
    "            cut.append(cut1[-1]+1)\n",
    "            x_woe=pd.cut(X,cut,right=False,labels=woe)\n",
    "            return  d3,cut,woe,iv,x_woe\n",
    "        else:\n",
    "            dn1 = pd.DataFrame({\"X\": X, \"Y\": Y, \"Bucket\": pd.cut(X, 100)})\n",
    "            dn2 = dn1.groupby('Bucket', as_index = False)\n",
    "            dn3 = pd.DataFrame(dn2.X.min(), columns = ['min'])\n",
    "            dn3['min']=dn2.min().X    \n",
    "            dn3['max'] = dn2.max().X\n",
    "            dn3['sum'] = dn2.sum().Y\n",
    "            dn3['total'] = dn2.count().Y\n",
    "            while (1):\n",
    "                    if  (len(dn3)>4):\n",
    "                        dn3_min_index = dn3[dn3.total == min(dn3.total)].index.values[0]\n",
    "                        if (dn3_min_index!=0):    #最小值非第一行的情况\n",
    "                            dn3.iloc[dn3_min_index-1, 1] =dn3.iloc[dn3_min_index, 1] \n",
    "                            dn3.iloc[dn3_min_index-1, 2] = dn3.iloc[dn3_min_index, 2] +dn3.iloc[dn3_min_index-1, 2]\n",
    "                            dn3.iloc[dn3_min_index-1, 3] = dn3.iloc[dn3_min_index, 3] +dn3.iloc[dn3_min_index-1, 3]\n",
    "                            dn3=dn3.drop([dn3_min_index])\n",
    "                            dn3= dn3.reset_index(drop=True)\n",
    "                        else:    #最小值是第一行的情况\n",
    "                            dn3.iloc[dn3_min_index+1, 0] =dn3.iloc[dn3_min_index, 0] \n",
    "                            dn3.iloc[dn3_min_index+1, 2] = dn3.iloc[dn3_min_index, 2] +dn3.iloc[dn3_min_index+1, 2]\n",
    "                            dn3.iloc[dn3_min_index+1, 3] = dn3.iloc[dn3_min_index, 3] +dn3.iloc[dn3_min_index+1, 3]\n",
    "                            dn3=dn3.drop([dn3_min_index])\n",
    "                            dn3= dn3.reset_index(drop=True)\n",
    "                    else:\n",
    "                        break\n",
    "            dn3['bad_rate'] =dn3['sum']/dn3['total']\n",
    "            dn3['group_rate']=dn3['total']/(bad+good)\n",
    "            dn3['woe']=np.log((dn3['bad_rate']/(1-dn3['bad_rate']))/(bad/good))\n",
    "            dn3['iv']=(dn3['sum']/bad-((dn3['total']-dn3['sum'])/good))*dn3['woe']\n",
    "            \n",
    "            iv=dn3['iv'].sum()\n",
    "            dn3['iv_sum']=iv\n",
    "            woe=list(dn3['woe'].round(6)) \n",
    "            cut=list(dn3['min'].round(6))\n",
    "            cut1=list(dn3['max'].round(6))\n",
    "            cut.append(cut1[-1]+1)\n",
    "            x_woe=pd.cut(X,cut,right=False,labels=woe)\n",
    "            return  dn3,cut,woe,iv,x_woe\n",
    "    else : \n",
    "        bad=Y.sum()      #坏客户数\n",
    "        good=Y.count()-bad  #好客户数\n",
    "        d1 = pd.DataFrame({\"X\": X, \"Y\": Y})\n",
    "        d2 = d1.groupby('X', as_index =True)\n",
    "        d3 = pd.DataFrame()\n",
    "        \n",
    "        d3['sum'] = d2.sum().Y\n",
    "        d3['total'] = d2.count().Y\n",
    "        for c in range(d3.shape[0])[::-1]:\n",
    "            if ((d3.iloc[c,1]-d3.iloc[c,0])==0) or (d3.iloc[c,0]==0):\n",
    "                d3.iloc[c-1,0]=d3.iloc[c-1,0]+d3.iloc[c,0]\n",
    "                d3.iloc[c-1,1]=d3.iloc[c-1,1]+d3.iloc[c,1]\n",
    "                d3.drop(d3.index[c],inplace=True)\n",
    "            else:\n",
    "                continue\n",
    "        \n",
    "        d3['min']=d3.index  \n",
    "        d3['max'] = d3.index\n",
    "        d3['bad_rate'] =d3['sum']/d3['total']\n",
    "        d3['group_rate']=d3['total']/(bad+good)\n",
    "        d3['woe']=np.log((d3['bad_rate']/(1-d3['bad_rate']))/(bad/good))\n",
    "        d3['iv']=(d3['sum']/bad-((d3['total']-d3['sum'])/good))*d3['woe']\n",
    "        iv=d3['iv'].sum()\n",
    "        d3['iv_sum']=iv\n",
    "        d3=d3[['min','max','sum','total','bad_rate','group_rate','woe','iv','iv_sum']]\n",
    "        \n",
    "        \n",
    "        woe=list(d3['woe'].round(6))\n",
    "        cut=list(d3.index)\n",
    "        x_woe=X.replace(cut,woe)\n",
    "        return d3,cut,woe,iv,x_woe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_x = train.drop(['x_89','x_93','x_95'],axis =1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         0.436170\n",
       "1         0.297872\n",
       "2         0.372340\n",
       "3         0.053191\n",
       "4         0.095745\n",
       "5         0.148936\n",
       "6         0.382979\n",
       "7         0.180851\n",
       "8         0.074468\n",
       "9         0.255319\n",
       "10        0.734043\n",
       "11        0.170213\n",
       "12        0.170213\n",
       "13        0.500000\n",
       "14        0.276596\n",
       "15        0.340426\n",
       "16        0.170213\n",
       "17        0.382979\n",
       "18        0.053191\n",
       "19        0.202128\n",
       "20        0.106383\n",
       "21        0.680851\n",
       "22        0.351064\n",
       "23      -99.000000\n",
       "24        0.170213\n",
       "25        0.180851\n",
       "26        0.627660\n",
       "27        0.106383\n",
       "28        0.446809\n",
       "29        0.755319\n",
       "           ...    \n",
       "13572     0.680851\n",
       "13573     0.404255\n",
       "13574     0.308511\n",
       "13575     0.606383\n",
       "13576     0.361702\n",
       "13577     0.361702\n",
       "13578     0.414894\n",
       "13579     0.361702\n",
       "13580     0.117021\n",
       "13581     0.404255\n",
       "13582     0.382979\n",
       "13583     0.414894\n",
       "13584     0.808511\n",
       "13585     0.712766\n",
       "13586     0.265957\n",
       "13587     0.680851\n",
       "13588     0.244681\n",
       "13589     0.627660\n",
       "13590     0.265957\n",
       "13591     0.202128\n",
       "13592     0.234043\n",
       "13593     0.329787\n",
       "13594     0.755319\n",
       "13595     0.244681\n",
       "13596     0.563830\n",
       "13597     0.553191\n",
       "13598     0.521277\n",
       "13599     0.297872\n",
       "13600     0.563830\n",
       "13601     0.531915\n",
       "Name: x_95, Length: 13602, dtype: float64"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['x_95']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x_1\n",
      "**********\n",
      "x_1\n",
      "$$$$$$$$$$\n",
      "x_2\n",
      "**********\n",
      "x_2\n",
      "$$$$$$$$$$\n",
      "x_3\n",
      "**********\n",
      "x_3\n",
      "$$$$$$$$$$\n",
      "x_4\n",
      "**********\n",
      "x_4\n",
      "$$$$$$$$$$\n",
      "x_5\n",
      "**********\n",
      "x_5\n",
      "$$$$$$$$$$\n",
      "x_6\n",
      "**********\n",
      "x_6\n",
      "$$$$$$$$$$\n",
      "x_7\n",
      "**********\n",
      "x_7\n",
      "$$$$$$$$$$\n",
      "x_8\n",
      "**********\n",
      "x_8\n",
      "$$$$$$$$$$\n",
      "x_9\n",
      "**********\n",
      "x_9\n",
      "$$$$$$$$$$\n",
      "x_10\n",
      "**********\n",
      "x_10\n",
      "$$$$$$$$$$\n",
      "x_11\n",
      "**********\n",
      "x_11\n",
      "$$$$$$$$$$\n",
      "x_12\n",
      "**********\n",
      "x_12\n",
      "$$$$$$$$$$\n",
      "x_13\n",
      "**********\n",
      "x_13\n",
      "$$$$$$$$$$\n",
      "x_14\n",
      "**********\n",
      "x_14\n",
      "$$$$$$$$$$\n",
      "x_15\n",
      "**********\n",
      "x_15\n",
      "$$$$$$$$$$\n",
      "x_16\n",
      "**********\n",
      "x_16\n",
      "$$$$$$$$$$\n",
      "x_17\n",
      "**********\n",
      "x_17\n",
      "$$$$$$$$$$\n",
      "x_18\n",
      "**********\n",
      "x_18\n",
      "$$$$$$$$$$\n",
      "x_19\n",
      "**********\n",
      "x_19\n",
      "$$$$$$$$$$\n",
      "x_20\n",
      "**********\n",
      "x_20\n",
      "$$$$$$$$$$\n",
      "x_21\n",
      "**********\n",
      "x_21\n",
      "$$$$$$$$$$\n",
      "x_22\n",
      "**********\n",
      "x_22\n",
      "$$$$$$$$$$\n",
      "x_23\n",
      "**********\n",
      "x_23\n",
      "$$$$$$$$$$\n",
      "x_24\n",
      "**********\n",
      "x_24\n",
      "$$$$$$$$$$\n",
      "x_25\n",
      "**********\n",
      "x_25\n",
      "$$$$$$$$$$\n",
      "x_26\n",
      "**********\n",
      "x_26\n",
      "$$$$$$$$$$\n",
      "x_27\n",
      "**********\n",
      "x_27\n",
      "$$$$$$$$$$\n",
      "x_28\n",
      "**********\n",
      "x_28\n",
      "$$$$$$$$$$\n",
      "x_29\n",
      "**********\n",
      "x_29\n",
      "$$$$$$$$$$\n",
      "x_30\n",
      "**********\n",
      "x_30\n",
      "$$$$$$$$$$\n",
      "x_31\n",
      "**********\n",
      "x_31\n",
      "$$$$$$$$$$\n",
      "x_32\n",
      "**********\n",
      "x_32\n",
      "$$$$$$$$$$\n",
      "x_33\n",
      "**********\n",
      "x_33\n",
      "$$$$$$$$$$\n",
      "x_34\n",
      "**********\n",
      "x_34\n",
      "$$$$$$$$$$\n",
      "x_35\n",
      "**********\n",
      "x_35\n",
      "$$$$$$$$$$\n",
      "x_36\n",
      "**********\n",
      "x_36\n",
      "$$$$$$$$$$\n",
      "x_37\n",
      "**********\n",
      "x_37\n",
      "$$$$$$$$$$\n",
      "x_38\n",
      "**********\n",
      "x_38\n",
      "$$$$$$$$$$\n",
      "x_39\n",
      "**********\n",
      "x_39\n",
      "$$$$$$$$$$\n",
      "x_40\n",
      "**********\n",
      "x_40\n",
      "$$$$$$$$$$\n",
      "x_41\n",
      "**********\n",
      "x_41\n",
      "$$$$$$$$$$\n",
      "x_42\n",
      "**********\n",
      "x_42\n",
      "$$$$$$$$$$\n",
      "x_43\n",
      "**********\n",
      "x_43\n",
      "$$$$$$$$$$\n",
      "x_44\n",
      "**********\n",
      "x_44\n",
      "$$$$$$$$$$\n",
      "x_45\n",
      "**********\n",
      "x_45\n",
      "$$$$$$$$$$\n",
      "x_46\n",
      "**********\n",
      "x_46\n",
      "$$$$$$$$$$\n",
      "x_47\n",
      "**********\n",
      "x_47\n",
      "$$$$$$$$$$\n",
      "x_48\n",
      "**********\n",
      "x_48\n",
      "$$$$$$$$$$\n",
      "x_49\n",
      "**********\n",
      "x_49\n",
      "$$$$$$$$$$\n",
      "x_50\n",
      "**********\n",
      "x_50\n",
      "$$$$$$$$$$\n",
      "x_51\n",
      "**********\n",
      "x_51\n",
      "$$$$$$$$$$\n",
      "x_52\n",
      "**********\n",
      "x_52\n",
      "$$$$$$$$$$\n",
      "x_53\n",
      "**********\n",
      "x_53\n",
      "$$$$$$$$$$\n",
      "x_54\n",
      "**********\n",
      "x_54\n",
      "$$$$$$$$$$\n",
      "x_55\n",
      "**********\n",
      "x_55\n",
      "$$$$$$$$$$\n",
      "x_56\n",
      "**********\n",
      "x_56\n",
      "$$$$$$$$$$\n",
      "x_57\n",
      "**********\n",
      "x_57\n",
      "$$$$$$$$$$\n",
      "x_58\n",
      "**********\n",
      "x_58\n",
      "$$$$$$$$$$\n",
      "x_59\n",
      "**********\n",
      "x_59\n",
      "$$$$$$$$$$\n",
      "x_60\n",
      "**********\n",
      "x_60\n",
      "$$$$$$$$$$\n",
      "x_61\n",
      "**********\n",
      "x_61\n",
      "$$$$$$$$$$\n",
      "x_62\n",
      "**********\n",
      "x_62\n",
      "$$$$$$$$$$\n",
      "x_63\n",
      "**********\n",
      "x_63\n",
      "$$$$$$$$$$\n",
      "x_64\n",
      "**********\n",
      "x_64\n",
      "$$$$$$$$$$\n",
      "x_65\n",
      "**********\n",
      "x_65\n",
      "$$$$$$$$$$\n",
      "x_66\n",
      "**********\n",
      "x_66\n",
      "$$$$$$$$$$\n",
      "x_67\n",
      "**********\n",
      "x_67\n",
      "$$$$$$$$$$\n",
      "x_68\n",
      "**********\n",
      "x_68\n",
      "$$$$$$$$$$\n",
      "x_69\n",
      "**********\n",
      "x_69\n",
      "$$$$$$$$$$\n",
      "x_70\n",
      "**********\n",
      "x_70\n",
      "$$$$$$$$$$\n",
      "x_71\n",
      "**********\n",
      "x_71\n",
      "$$$$$$$$$$\n",
      "x_72\n",
      "**********\n",
      "x_72\n",
      "$$$$$$$$$$\n",
      "x_73\n",
      "**********\n",
      "x_73\n",
      "$$$$$$$$$$\n",
      "x_74\n",
      "**********\n",
      "x_74\n",
      "$$$$$$$$$$\n",
      "x_75\n",
      "**********\n",
      "x_75\n",
      "$$$$$$$$$$\n",
      "x_76\n",
      "**********\n",
      "x_76\n",
      "$$$$$$$$$$\n",
      "x_77\n",
      "**********\n",
      "x_77\n",
      "$$$$$$$$$$\n",
      "x_78\n",
      "**********\n",
      "x_78\n",
      "$$$$$$$$$$\n",
      "x_79\n",
      "**********\n",
      "x_79\n",
      "$$$$$$$$$$\n",
      "x_80\n",
      "**********\n",
      "x_80\n",
      "$$$$$$$$$$\n",
      "x_81\n",
      "**********\n",
      "x_81\n",
      "$$$$$$$$$$\n",
      "x_82\n",
      "**********\n",
      "x_82\n",
      "$$$$$$$$$$\n",
      "x_83\n",
      "**********\n",
      "x_83\n",
      "$$$$$$$$$$\n",
      "x_84\n",
      "**********\n",
      "x_84\n",
      "$$$$$$$$$$\n",
      "x_85\n",
      "**********\n",
      "x_85\n",
      "$$$$$$$$$$\n",
      "x_86\n",
      "**********\n",
      "x_86\n",
      "$$$$$$$$$$\n",
      "x_87\n",
      "**********\n",
      "x_87\n",
      "$$$$$$$$$$\n",
      "x_88\n",
      "**********\n",
      "x_88\n",
      "$$$$$$$$$$\n",
      "x_89\n",
      "**********\n",
      "x_90\n",
      "**********\n",
      "x_90\n",
      "$$$$$$$$$$\n",
      "x_91\n",
      "**********\n",
      "x_91\n",
      "$$$$$$$$$$\n",
      "x_92\n",
      "**********\n",
      "x_93\n",
      "**********\n",
      "x_94\n",
      "**********\n",
      "x_95\n",
      "**********\n",
      "x_96\n",
      "**********\n",
      "x_96\n",
      "$$$$$$$$$$\n",
      "x_97\n",
      "**********\n",
      "x_97\n",
      "$$$$$$$$$$\n",
      "x_98\n",
      "**********\n",
      "x_98\n",
      "$$$$$$$$$$\n",
      "x_99\n",
      "**********\n",
      "x_99\n",
      "$$$$$$$$$$\n",
      "x_100\n",
      "**********\n",
      "x_100\n",
      "$$$$$$$$$$\n",
      "x_101\n",
      "**********\n",
      "x_101\n",
      "$$$$$$$$$$\n",
      "x_102\n",
      "**********\n",
      "x_103\n",
      "**********\n",
      "x_104\n",
      "**********\n",
      "x_105\n",
      "**********\n",
      "x_106\n",
      "**********\n",
      "x_107\n",
      "**********\n",
      "x_108\n",
      "**********\n",
      "x_109\n",
      "**********\n",
      "x_110\n",
      "**********\n",
      "x_111\n",
      "**********\n",
      "x_112\n",
      "**********\n",
      "x_113\n",
      "**********\n",
      "x_114\n",
      "**********\n",
      "x_115\n",
      "**********\n",
      "x_116\n",
      "**********\n",
      "x_117\n",
      "**********\n",
      "x_118\n",
      "**********\n",
      "x_119\n",
      "**********\n",
      "x_120\n",
      "**********\n",
      "x_121\n",
      "**********\n",
      "x_122\n",
      "**********\n",
      "x_123\n",
      "**********\n",
      "x_124\n",
      "**********\n",
      "x_125\n",
      "**********\n",
      "x_126\n",
      "**********\n",
      "x_127\n",
      "**********\n",
      "x_128\n",
      "**********\n",
      "x_129\n",
      "**********\n",
      "x_130\n",
      "**********\n",
      "x_131\n",
      "**********\n",
      "x_132\n",
      "**********\n",
      "x_133\n",
      "**********\n",
      "x_134\n",
      "**********\n",
      "x_135\n",
      "**********\n",
      "x_136\n",
      "**********\n",
      "x_137\n",
      "**********\n",
      "x_138\n",
      "**********\n",
      "x_139\n",
      "**********\n",
      "x_139\n",
      "$$$$$$$$$$\n",
      "x_140\n",
      "**********\n",
      "x_140\n",
      "$$$$$$$$$$\n",
      "x_141\n",
      "**********\n",
      "x_141\n",
      "$$$$$$$$$$\n",
      "x_142\n",
      "**********\n",
      "x_142\n",
      "$$$$$$$$$$\n",
      "x_143\n",
      "**********\n",
      "x_143\n",
      "$$$$$$$$$$\n",
      "x_144\n",
      "**********\n",
      "x_144\n",
      "$$$$$$$$$$\n",
      "x_145\n",
      "**********\n",
      "x_145\n",
      "$$$$$$$$$$\n",
      "x_146\n",
      "**********\n",
      "x_146\n",
      "$$$$$$$$$$\n",
      "x_147\n",
      "**********\n",
      "x_147\n",
      "$$$$$$$$$$\n",
      "x_148\n",
      "**********\n",
      "x_148\n",
      "$$$$$$$$$$\n",
      "x_149\n",
      "**********\n",
      "x_149\n",
      "$$$$$$$$$$\n",
      "x_150\n",
      "**********\n",
      "x_150\n",
      "$$$$$$$$$$\n",
      "x_151\n",
      "**********\n",
      "x_151\n",
      "$$$$$$$$$$\n",
      "x_152\n",
      "**********\n",
      "x_152\n",
      "$$$$$$$$$$\n",
      "x_153\n",
      "**********\n",
      "x_153\n",
      "$$$$$$$$$$\n",
      "x_154\n",
      "**********\n",
      "x_154\n",
      "$$$$$$$$$$\n",
      "x_155\n",
      "**********\n",
      "x_155\n",
      "$$$$$$$$$$\n",
      "x_156\n",
      "**********\n",
      "x_156\n",
      "$$$$$$$$$$\n",
      "x_157\n",
      "**********\n",
      "x_157\n",
      "$$$$$$$$$$\n"
     ]
    }
   ],
   "source": [
    "iv_all = []\n",
    "for i in range(1,158):\n",
    "    col = 'x'+'_'+str(i)\n",
    "    print(col)\n",
    "    print('**********')\n",
    "    if col in train_x.columns.values:\n",
    "        print(col)\n",
    "        print('$$$$$$$$$$')\n",
    "        X = train_x[col]\n",
    "        iv =  woe_single(train_x,train_x.y,X)[3]\n",
    "        iv_all.append(iv)        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "iviv = pd.DataFrame(iv_all)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.014330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.008230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.142508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.157673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.160702</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.142492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.235565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.265917</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.145211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.154975</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.155253</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.145172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.243998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.254502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.142545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.161076</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.151310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0.142492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.253922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.261937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.145172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>0.154899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0.145172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.276438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>0.142545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.161102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>0.160804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>0.142492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.140277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>0.139582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>0.092811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>0.118182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>0.134821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>0.027570</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>0.006506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>0.011616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>0.182021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>0.059052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>0.095420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>0.082009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>0.058184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0.020071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>0.331784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>0.400351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>0.335311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>0.036954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>0.097523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>102</th>\n",
       "      <td>0.005817</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>0.019236</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107</th>\n",
       "      <td>0.030210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>0.030615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>0.028521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>0.033363</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>0.012526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>0.186658</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>115 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            0\n",
       "0    0.014330\n",
       "1    0.008230\n",
       "2    0.142508\n",
       "3    0.157673\n",
       "4    0.160702\n",
       "5    0.142492\n",
       "6    0.235565\n",
       "7    0.265917\n",
       "8    0.145211\n",
       "9    0.154975\n",
       "10   0.155253\n",
       "11   0.145172\n",
       "12   0.243998\n",
       "13   0.254502\n",
       "14   0.142545\n",
       "15   0.161076\n",
       "16   0.151310\n",
       "17   0.142492\n",
       "18   0.253922\n",
       "19   0.261937\n",
       "20   0.145172\n",
       "21   0.154899\n",
       "22   0.145172\n",
       "23   0.276438\n",
       "24   0.142545\n",
       "25   0.161102\n",
       "26   0.160804\n",
       "27   0.142492\n",
       "28   0.140277\n",
       "29   0.139582\n",
       "..        ...\n",
       "85   0.092811\n",
       "86   0.118182\n",
       "87   0.134821\n",
       "88   0.027570\n",
       "89   0.006506\n",
       "90   0.011616\n",
       "91   0.182021\n",
       "92   0.059052\n",
       "93   0.095420\n",
       "94   0.082009\n",
       "95   0.058184\n",
       "96   0.020071\n",
       "97   0.331784\n",
       "98   0.400351\n",
       "99   0.335311\n",
       "100  0.036954\n",
       "101  0.097523\n",
       "102  0.005817\n",
       "103  0.000000\n",
       "104  0.000000\n",
       "105  0.000000\n",
       "106  0.019236\n",
       "107  0.030210\n",
       "108  0.000000\n",
       "109  0.000000\n",
       "110  0.030615\n",
       "111  0.028521\n",
       "112  0.033363\n",
       "113  0.012526\n",
       "114  0.186658\n",
       "\n",
       "[115 rows x 1 columns]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iviv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "iviv.columns = ['iv']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "aa = iviv[iviv.iv>0.02]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(101, 1)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>iv</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.142508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.157673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.160702</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.142492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.235565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.265917</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.145211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.154975</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.155253</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.145172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.243998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.254502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.142545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.161076</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.151310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0.142492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.253922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.261937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.145172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>0.154899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0.145172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.276438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>0.142545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.161102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>0.160804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>0.142492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.140277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>0.139582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>0.145172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>0.161490</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>0.082866</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>0.060483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>0.055108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>0.219054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>0.380261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>0.913255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>0.110968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>0.149276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>0.170560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>0.063174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>0.092811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>0.118182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>0.134821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>0.027570</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>0.182021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>0.059052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>0.095420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>0.082009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>0.058184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0.020071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>0.331784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>0.400351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>0.335311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>0.036954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>0.097523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107</th>\n",
       "      <td>0.030210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>0.030615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>0.028521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>0.033363</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>0.186658</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>101 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           iv\n",
       "2    0.142508\n",
       "3    0.157673\n",
       "4    0.160702\n",
       "5    0.142492\n",
       "6    0.235565\n",
       "7    0.265917\n",
       "8    0.145211\n",
       "9    0.154975\n",
       "10   0.155253\n",
       "11   0.145172\n",
       "12   0.243998\n",
       "13   0.254502\n",
       "14   0.142545\n",
       "15   0.161076\n",
       "16   0.151310\n",
       "17   0.142492\n",
       "18   0.253922\n",
       "19   0.261937\n",
       "20   0.145172\n",
       "21   0.154899\n",
       "22   0.145172\n",
       "23   0.276438\n",
       "24   0.142545\n",
       "25   0.161102\n",
       "26   0.160804\n",
       "27   0.142492\n",
       "28   0.140277\n",
       "29   0.139582\n",
       "30   0.145172\n",
       "31   0.161490\n",
       "..        ...\n",
       "74   0.082866\n",
       "75   0.060483\n",
       "76   0.055108\n",
       "77   0.219054\n",
       "78   0.380261\n",
       "79   0.913255\n",
       "81   0.110968\n",
       "82   0.149276\n",
       "83   0.170560\n",
       "84   0.063174\n",
       "85   0.092811\n",
       "86   0.118182\n",
       "87   0.134821\n",
       "88   0.027570\n",
       "91   0.182021\n",
       "92   0.059052\n",
       "93   0.095420\n",
       "94   0.082009\n",
       "95   0.058184\n",
       "96   0.020071\n",
       "97   0.331784\n",
       "98   0.400351\n",
       "99   0.335311\n",
       "100  0.036954\n",
       "101  0.097523\n",
       "107  0.030210\n",
       "110  0.030615\n",
       "111  0.028521\n",
       "112  0.033363\n",
       "114  0.186658\n",
       "\n",
       "[101 rows x 1 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.01433045, 0.00822979, 0.14250822, 0.15767271, 0.16070201,\n",
       "       0.14249238, 0.2355655 , 0.26591722, 0.14521082, 0.15497532,\n",
       "       0.15525331, 0.14517174, 0.24399771, 0.25450171, 0.14254536,\n",
       "       0.1610757 , 0.15130971, 0.14249238, 0.25392164, 0.26193705,\n",
       "       0.14517174, 0.15489927, 0.14517174, 0.27643831, 0.14254536,\n",
       "       0.16110169, 0.16080431, 0.14249238, 0.14027735, 0.13958204,\n",
       "       0.14517174, 0.1614905 , 0.15644728, 0.14517174, 0.18942682,\n",
       "       0.18800187, 0.15673193, 0.28466877, 0.22682747, 0.41254442,\n",
       "       0.32857291, 0.12461392, 0.19467278, 0.22394503, 0.1443279 ,\n",
       "       0.25819756, 0.17893846, 0.04024157, 0.00196115, 0.18357232,\n",
       "       0.30958973, 0.29415167, 0.33587353, 0.15542169, 0.19835067,\n",
       "       0.21881392, 0.16021132, 0.08972257, 0.09015788, 0.15764378,\n",
       "       0.18266489, 0.25285018, 0.24243243, 0.1822766 , 0.22036515,\n",
       "       0.23791938, 0.27808418, 0.37549146, 0.32629029, 0.04733034,\n",
       "       0.04768453, 0.09817676, 0.09524105, 0.08311285, 0.08286624,\n",
       "       0.0604828 , 0.05510832, 0.21905384, 0.38026082, 0.91325458,\n",
       "       0.01429533, 0.11096791, 0.14927611, 0.17055997, 0.06317439,\n",
       "       0.09281143, 0.11818167, 0.13482071, 0.02757042, 0.00650568,\n",
       "       0.01161618, 0.18202052, 0.05905151, 0.09541961, 0.08200869,\n",
       "       0.05818439, 0.02007112, 0.33178417, 0.40035086, 0.33531109,\n",
       "       0.03695352, 0.09752291, 0.00581742, 0.        , 0.        ,\n",
       "       0.        , 0.01923645, 0.03021007, 0.        , 0.        ,\n",
       "       0.03061478, 0.0285214 , 0.03336298, 0.01252577, 0.18665835])"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(iviv.iv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['cust_id', 'cust_group', 'y', 'x_1', 'x_2', 'x_3', 'x_4', 'x_5',\n",
       "       'x_6', 'x_7', 'x_8', 'x_9', 'x_10', 'x_11', 'x_12', 'x_13', 'x_14',\n",
       "       'x_15', 'x_16', 'x_17', 'x_18', 'x_19', 'x_20', 'x_21', 'x_22',\n",
       "       'x_23', 'x_24', 'x_25', 'x_26', 'x_27', 'x_28', 'x_29', 'x_30',\n",
       "       'x_31', 'x_32', 'x_33', 'x_34', 'x_35', 'x_36', 'x_37', 'x_38',\n",
       "       'x_39', 'x_40', 'x_41', 'x_42', 'x_43', 'x_44', 'x_45', 'x_46',\n",
       "       'x_47', 'x_48', 'x_49', 'x_50', 'x_51', 'x_52', 'x_53', 'x_54',\n",
       "       'x_55', 'x_56', 'x_57', 'x_58', 'x_59', 'x_60', 'x_61', 'x_62',\n",
       "       'x_63', 'x_64', 'x_65', 'x_66', 'x_67', 'x_68', 'x_69', 'x_70',\n",
       "       'x_71', 'x_72', 'x_73', 'x_74', 'x_75', 'x_76', 'x_77', 'x_78',\n",
       "       'x_79', 'x_80', 'x_81', 'x_82', 'x_83', 'x_84', 'x_85', 'x_86',\n",
       "       'x_87', 'x_88', 'x_89', 'x_90', 'x_91', 'x_93', 'x_95', 'x_96',\n",
       "       'x_97', 'x_98', 'x_99', 'x_100', 'x_101', 'x_139', 'x_140',\n",
       "       'x_141', 'x_142', 'x_143', 'x_144', 'x_145', 'x_146', 'x_147',\n",
       "       'x_148', 'x_149', 'x_150', 'x_151', 'x_152', 'x_153', 'x_154',\n",
       "       'x_155', 'x_156', 'x_157'], dtype=object)"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.columns.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cust_id</th>\n",
       "      <th>cust_group</th>\n",
       "      <th>y</th>\n",
       "      <th>x_1</th>\n",
       "      <th>x_2</th>\n",
       "      <th>x_3</th>\n",
       "      <th>x_4</th>\n",
       "      <th>x_5</th>\n",
       "      <th>x_6</th>\n",
       "      <th>x_7</th>\n",
       "      <th>...</th>\n",
       "      <th>x_148</th>\n",
       "      <th>x_149</th>\n",
       "      <th>x_150</th>\n",
       "      <th>x_151</th>\n",
       "      <th>x_152</th>\n",
       "      <th>x_153</th>\n",
       "      <th>x_154</th>\n",
       "      <th>x_155</th>\n",
       "      <th>x_156</th>\n",
       "      <th>x_157</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>110000</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.354167</td>\n",
       "      <td>0.604988</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>-99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>110001</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.125000</td>\n",
       "      <td>0.012058</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>110002</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.565979</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>110003</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.316209</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>110004</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.008061</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 121 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   cust_id cust_group  y       x_1       x_2  x_3  x_4  x_5  x_6  x_7  ...    \\\n",
       "0   110000    group_3  0  0.354167  0.604988  -99  -99  -99  -99  -99  ...     \n",
       "1   110001    group_3  0  0.125000  0.012058  -99  -99  -99  -99  -99  ...     \n",
       "2   110002    group_3  0  0.333333  0.565979    0    0    0    0    0  ...     \n",
       "3   110003    group_3  0  0.208333  0.316209    0    0    0    0    1  ...     \n",
       "4   110004    group_3  0  0.208333  0.008061  -99  -99  -99  -99  -99  ...     \n",
       "\n",
       "   x_148  x_149  x_150  x_151  x_152  x_153  x_154  x_155  x_156  x_157  \n",
       "0      1      1      1      1      1      1      1      1      3    -99  \n",
       "1      1      1      1      1      1      1      1      1      2      2  \n",
       "2      1      1      2      1      1      1      1      1      2      2  \n",
       "3      2      1      1      1      1      1      1      1      2      4  \n",
       "4      1      1      1      1      1      1      1      1      2      1  \n",
       "\n",
       "[5 rows x 121 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "iv_low_col = ['x_89','x_93','x_95','x_1','x_2','x_49','x_91','x_96','x_145','x_146','x_147','x_148','x_151','x_152','x_156']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(13602, 106)\n",
      "(8122, 105)\n"
     ]
    }
   ],
   "source": [
    "train_iv = train.drop(iv_low_col,axis=1)\n",
    "test_iv = test.drop(iv_low_col,axis=1)\n",
    "print(train_iv.shape)\n",
    "print(test_iv.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "iv_all = []\n",
    "for i in range(1,158):\n",
    "    col = 'x'+'_'+str(i)\n",
    "    print(col)\n",
    "    print('**********')\n",
    "    if col in train_x.columns.values:\n",
    "        print(col)\n",
    "        print('$$$$$$$$$$')\n",
    "        X = train_x[col]\n",
    "        iv =  woe_single(train_x,train_x.y,X)[3]\n",
    "        iv_all.append(iv)        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "def woe_all(DF,Y,X):\n",
    "    for i in X:\n",
    "        if DF[i].nunique()>11:\n",
    "            r = 0\n",
    "            bad=Y.sum()      #坏客户数(假设因变量列为1的是坏客户)\n",
    "            good=Y.count()-bad  #好客户数\n",
    "            n=5\n",
    "            while np.abs(r) < 1:\n",
    "                d1 = pd.DataFrame({\"X\": DF[i], \"Y\": Y, \"Bucket\": pd.qcut(DF[i], n,duplicates='drop')})\n",
    "                d2 = d1.groupby('Bucket', as_index = False)\n",
    "                r, p = stats.spearmanr(d2.mean().X, d2.mean().Y)\n",
    "                n = n - 1\n",
    "            d3 = pd.DataFrame(d2.X.min(), columns = ['min'])\n",
    "            d3['min']=d2.min().X    \n",
    "            d3['max'] = d2.max().X\n",
    "            d3['sum'] = d2.sum().Y\n",
    "            d3['total'] = d2.count().Y\n",
    "            d3['bad_rate'] = d2.mean().Y\n",
    "            d3['group_rate']=d3['total']/(bad+good)\n",
    "            d3['woe']=np.log((d3['bad_rate']/(1-d3['bad_rate']))/(bad/good))\n",
    "            d3['iv']=(d3['sum']/bad-((d3['total']-d3['sum'])/good))*d3['woe']\n",
    "            iv=d3['iv'].sum()\n",
    "            if iv!=0.0:\n",
    "                woe=list(d3['woe'].round(5))\n",
    "                cut=list(d3['min'].round(5))\n",
    "                cut1=list(d3['max'].round(5))\n",
    "                cut.append(cut1[-1]+1)\n",
    "                x_woe=pd.cut(DF[i],cut,right=False,labels=woe)\n",
    "                DF[i]=x_woe\n",
    "            else:\n",
    "                dn1 = pd.DataFrame({\"X\": DF[i], \"Y\": Y, \"Bucket\": pd.cut(DF[i], 20)})\n",
    "                dn2 = dn1.groupby('Bucket', as_index = False)\n",
    "                dn3 = pd.DataFrame(dn2.X.min(), columns = ['min'])\n",
    "                dn3['min']=dn2.min().X    \n",
    "                dn3['max'] = dn2.max().X\n",
    "                dn3['sum'] = dn2.sum().Y\n",
    "                dn3['total'] = dn2.count().Y\n",
    "                dn3=dn3.dropna()\n",
    "                dn3= dn3.reset_index(drop=True)\n",
    "                while (1):\n",
    "                    if  (len(dn3)>4):\n",
    "                        dn3_min_index = dn3[dn3.total == min(dn3.total)].index.values[0]\n",
    "                        if (dn3_min_index!=0):    #最小值非第一行的情况\n",
    "                            dn3.iloc[dn3_min_index-1, 1] =dn3.iloc[dn3_min_index, 1] \n",
    "                            dn3.iloc[dn3_min_index-1, 2] = dn3.iloc[dn3_min_index, 2] +dn3.iloc[dn3_min_index-1, 2]\n",
    "                            dn3.iloc[dn3_min_index-1, 3] = dn3.iloc[dn3_min_index, 3] +dn3.iloc[dn3_min_index-1, 3]\n",
    "                            dn3=dn3.drop([dn3_min_index])\n",
    "                            dn3= dn3.reset_index(drop=True)\n",
    "                        else:    #最小值是第一行的情况\n",
    "                            dn3.iloc[dn3_min_index+1, 0] =dn3.iloc[dn3_min_index, 0] \n",
    "                            dn3.iloc[dn3_min_index+1, 2] = dn3.iloc[dn3_min_index, 2] +dn3.iloc[dn3_min_index+1, 2]\n",
    "                            dn3.iloc[dn3_min_index+1, 3] = dn3.iloc[dn3_min_index, 3] +dn3.iloc[dn3_min_index+1, 3]\n",
    "                            dn3=dn3.drop([dn3_min_index])\n",
    "                            dn3= dn3.reset_index(drop=True)\n",
    "                    else:\n",
    "                        break\n",
    "                dn3['bad_rate'] =dn3['sum']/dn3['total']\n",
    "                dn3['group_rate']=dn3['total']/(bad+good)\n",
    "                dn3['woe']=np.log((dn3['bad_rate']/(1-dn3['bad_rate']))/(bad/good))\n",
    "                dn3['iv']=(dn3['sum']/bad-((dn3['total']-dn3['sum'])/good))*dn3['woe']\n",
    "                iv=dn3['iv'].sum()\n",
    "                woe=list(dn3['woe'].round(5)) \n",
    "                cut=list(dn3['min'].round(5))\n",
    "                cut1=list(dn3['max'].round(5))\n",
    "                cut.append(cut1[-1]+1)\n",
    "                x_woe=pd.cut(DF[i],cut,right=False,labels=woe)\n",
    "                DF[i]=x_woe\n",
    "        else : \n",
    "            bad=Y.sum()      #坏客户数\n",
    "            good=Y.count()-bad  #好客户数\n",
    "            d1 = pd.DataFrame({\"X\": DF[i], \"Y\": Y})\n",
    "            d2 = d1.groupby('X', as_index =True)\n",
    "            d3 = pd.DataFrame()\n",
    "            d3['sum'] = d2.sum().Y\n",
    "            d3['total'] = d2.count().Y\n",
    "            for c in range(d3.shape[0])[::-1]:\n",
    "                if ((d3.iloc[c,1]-d3.iloc[c,0])==0) or (d3.iloc[c,0]==0):\n",
    "                    d3.iloc[c-1,0]=d3.iloc[c-1,0]+d3.iloc[c,0]\n",
    "                    d3.iloc[c-1,1]=d3.iloc[c-1,1]+d3.iloc[c,1]\n",
    "                    d3.drop(d3.index[c],inplace=True)\n",
    "                else:\n",
    "                    continue\n",
    "            d3['bad_rate'] =d3['sum']/d3['total']\n",
    "            d3['group_rate']=d3['total']/(bad+good)\n",
    "            d3['woe']=np.log((d3['bad_rate']/(1-d3['bad_rate']))/(bad/good))\n",
    "            d3['iv']=(d3['sum']/bad-((d3['total']-d3['sum'])/good))*d3['woe']\n",
    "            iv=d3['iv'].sum()\n",
    "            woe=list(d3['woe'].round(5))\n",
    "            cut=list(d3.index)\n",
    "            x_woe=DF[i].replace(cut,woe)\n",
    "            DF[i]=x_woe\n",
    "    return DF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cust_id</th>\n",
       "      <th>cust_group</th>\n",
       "      <th>y</th>\n",
       "      <th>x_3</th>\n",
       "      <th>x_4</th>\n",
       "      <th>x_5</th>\n",
       "      <th>x_6</th>\n",
       "      <th>x_7</th>\n",
       "      <th>x_8</th>\n",
       "      <th>x_9</th>\n",
       "      <th>...</th>\n",
       "      <th>x_141</th>\n",
       "      <th>x_142</th>\n",
       "      <th>x_143</th>\n",
       "      <th>x_144</th>\n",
       "      <th>x_149</th>\n",
       "      <th>x_150</th>\n",
       "      <th>x_153</th>\n",
       "      <th>x_154</th>\n",
       "      <th>x_155</th>\n",
       "      <th>x_157</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>110000</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>-99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>110001</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>110002</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>110003</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>110004</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 106 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   cust_id cust_group  y  x_3  x_4  x_5  x_6  x_7  x_8  x_9  ...    x_141  \\\n",
       "0   110000    group_3  0  -99  -99  -99  -99  -99  -99  -99  ...        1   \n",
       "1   110001    group_3  0  -99  -99  -99  -99  -99  -99  -99  ...        5   \n",
       "2   110002    group_3  0    0    0    0    0    0    0    0  ...        6   \n",
       "3   110003    group_3  0    0    0    0    0    1    1    0  ...        1   \n",
       "4   110004    group_3  0  -99  -99  -99  -99  -99  -99    0  ...        4   \n",
       "\n",
       "   x_142  x_143  x_144  x_149  x_150  x_153  x_154  x_155  x_157  \n",
       "0      1      1      1      1      1      1      1      1    -99  \n",
       "1      1      1      2      1      1      1      1      1      2  \n",
       "2      1      2      2      1      2      1      1      1      2  \n",
       "3      1      2      2      1      1      1      1      1      4  \n",
       "4      2      1      1      1      1      1      1      1      1  \n",
       "\n",
       "[5 rows x 106 columns]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_iv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "train_woe=woe_all(train_iv,train_iv.y,train_iv.iloc[:,3:]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cust_id</th>\n",
       "      <th>cust_group</th>\n",
       "      <th>y</th>\n",
       "      <th>x_3</th>\n",
       "      <th>x_4</th>\n",
       "      <th>x_5</th>\n",
       "      <th>x_6</th>\n",
       "      <th>x_7</th>\n",
       "      <th>x_8</th>\n",
       "      <th>x_9</th>\n",
       "      <th>...</th>\n",
       "      <th>x_141</th>\n",
       "      <th>x_142</th>\n",
       "      <th>x_143</th>\n",
       "      <th>x_144</th>\n",
       "      <th>x_149</th>\n",
       "      <th>x_150</th>\n",
       "      <th>x_153</th>\n",
       "      <th>x_154</th>\n",
       "      <th>x_155</th>\n",
       "      <th>x_157</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>110000</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.34126</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.47405</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.64229</td>\n",
       "      <td>-0.8631</td>\n",
       "      <td>0.06545</td>\n",
       "      <td>0.15200</td>\n",
       "      <td>0.01618</td>\n",
       "      <td>0.04231</td>\n",
       "      <td>-0.03092</td>\n",
       "      <td>-0.04674</td>\n",
       "      <td>-0.05081</td>\n",
       "      <td>0.48512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>110001</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.34126</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.47405</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.58301</td>\n",
       "      <td>-0.8631</td>\n",
       "      <td>0.06545</td>\n",
       "      <td>-0.61568</td>\n",
       "      <td>0.01618</td>\n",
       "      <td>0.04231</td>\n",
       "      <td>-0.03092</td>\n",
       "      <td>-0.04674</td>\n",
       "      <td>-0.05081</td>\n",
       "      <td>-0.53025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>110002</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.32467</td>\n",
       "      <td>0.38674</td>\n",
       "      <td>0.38674</td>\n",
       "      <td>0.32427</td>\n",
       "      <td>-0.34126</td>\n",
       "      <td>-0.14754</td>\n",
       "      <td>0.31058</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.64889</td>\n",
       "      <td>-0.8631</td>\n",
       "      <td>-0.56633</td>\n",
       "      <td>-0.61568</td>\n",
       "      <td>0.01618</td>\n",
       "      <td>-0.74060</td>\n",
       "      <td>-0.03092</td>\n",
       "      <td>-0.04674</td>\n",
       "      <td>-0.05081</td>\n",
       "      <td>-0.53025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>110003</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0.32467</td>\n",
       "      <td>0.38674</td>\n",
       "      <td>0.38674</td>\n",
       "      <td>0.32427</td>\n",
       "      <td>0.38532</td>\n",
       "      <td>0.37991</td>\n",
       "      <td>0.31058</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.64229</td>\n",
       "      <td>-0.8631</td>\n",
       "      <td>-0.56633</td>\n",
       "      <td>-0.61568</td>\n",
       "      <td>0.01618</td>\n",
       "      <td>0.04231</td>\n",
       "      <td>-0.03092</td>\n",
       "      <td>-0.04674</td>\n",
       "      <td>-0.05081</td>\n",
       "      <td>-0.30746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>110004</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>-0.34126</td>\n",
       "      <td>-0.44469</td>\n",
       "      <td>0.31058</td>\n",
       "      <td>...</td>\n",
       "      <td>4.00000</td>\n",
       "      <td>-2.0381</td>\n",
       "      <td>0.06545</td>\n",
       "      <td>0.15200</td>\n",
       "      <td>0.01618</td>\n",
       "      <td>0.04231</td>\n",
       "      <td>-0.03092</td>\n",
       "      <td>-0.04674</td>\n",
       "      <td>-0.05081</td>\n",
       "      <td>-0.56774</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 106 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   cust_id cust_group  y      x_3      x_4      x_5      x_6      x_7  \\\n",
       "0   110000    group_3  0 -0.44469 -0.44469 -0.44469 -0.44469 -0.34126   \n",
       "1   110001    group_3  0 -0.44469 -0.44469 -0.44469 -0.44469 -0.34126   \n",
       "2   110002    group_3  0  0.32467  0.38674  0.38674  0.32427 -0.34126   \n",
       "3   110003    group_3  0  0.32467  0.38674  0.38674  0.32427  0.38532   \n",
       "4   110004    group_3  0 -0.44469 -0.44469 -0.44469 -0.44469 -0.34126   \n",
       "\n",
       "       x_8      x_9   ...       x_141   x_142    x_143    x_144    x_149  \\\n",
       "0 -0.44469 -0.47405   ...    -1.64229 -0.8631  0.06545  0.15200  0.01618   \n",
       "1 -0.44469 -0.47405   ...    -0.58301 -0.8631  0.06545 -0.61568  0.01618   \n",
       "2 -0.14754  0.31058   ...    -0.64889 -0.8631 -0.56633 -0.61568  0.01618   \n",
       "3  0.37991  0.31058   ...    -1.64229 -0.8631 -0.56633 -0.61568  0.01618   \n",
       "4 -0.44469  0.31058   ...     4.00000 -2.0381  0.06545  0.15200  0.01618   \n",
       "\n",
       "     x_150    x_153    x_154    x_155    x_157  \n",
       "0  0.04231 -0.03092 -0.04674 -0.05081  0.48512  \n",
       "1  0.04231 -0.03092 -0.04674 -0.05081 -0.53025  \n",
       "2 -0.74060 -0.03092 -0.04674 -0.05081 -0.53025  \n",
       "3  0.04231 -0.03092 -0.04674 -0.05081 -0.30746  \n",
       "4  0.04231 -0.03092 -0.04674 -0.05081 -0.56774  \n",
       "\n",
       "[5 rows x 106 columns]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_woe.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(13602, 106)"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_woe.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_woe.to_csv('../data/woe_feature_train_xy.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_iv.to_csv('../data/iv_feature_train_xy.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test_iv.to_csv('../data/iv_feature_test_x.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cust_id</th>\n",
       "      <th>cust_group</th>\n",
       "      <th>x_3</th>\n",
       "      <th>x_4</th>\n",
       "      <th>x_5</th>\n",
       "      <th>x_6</th>\n",
       "      <th>x_7</th>\n",
       "      <th>x_8</th>\n",
       "      <th>x_9</th>\n",
       "      <th>x_10</th>\n",
       "      <th>...</th>\n",
       "      <th>x_141</th>\n",
       "      <th>x_142</th>\n",
       "      <th>x_143</th>\n",
       "      <th>x_144</th>\n",
       "      <th>x_149</th>\n",
       "      <th>x_150</th>\n",
       "      <th>x_153</th>\n",
       "      <th>x_154</th>\n",
       "      <th>x_155</th>\n",
       "      <th>x_157</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100000</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100001</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>-99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100002</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>-99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100003</td>\n",
       "      <td>group_3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100004</td>\n",
       "      <td>group_3</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>...</td>\n",
       "      <td>-99</td>\n",
       "      <td>-99</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 105 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   cust_id cust_group  x_3  x_4  x_5  x_6  x_7  x_8  x_9  x_10  ...    x_141  \\\n",
       "0   100000    group_3    0    1    1    0    3    3    0     1  ...      -99   \n",
       "1   100001    group_3    0    0    0    0    0    0    0     0  ...      -99   \n",
       "2   100002    group_3    0    0    0    0    3    3    0     0  ...      -99   \n",
       "3   100003    group_3    0    0    0    0    0    0    0     1  ...      -99   \n",
       "4   100004    group_3  -99  -99  -99  -99  -99  -99  -99   -99  ...      -99   \n",
       "\n",
       "   x_142  x_143  x_144  x_149  x_150  x_153  x_154  x_155  x_157  \n",
       "0    -99      1      1      1      1      1      1      1      2  \n",
       "1    -99      1      2      1      4      1      1      1    -99  \n",
       "2    -99      1      1      1      1      1      1      1    -99  \n",
       "3    -99      1      1      1      1      1      2      2      2  \n",
       "4    -99      2      2      1      2      1      1      1      1  \n",
       "\n",
       "[5 rows x 105 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_iv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
